import {
	getToken,
} from '../utils/auth.js';


import store from '../store/index.js';

// 后台地址
export const base_url='http://192.168.0.101:8080';


//不加token的接口列表
const whiteList = [
	'/api//banner/list',
	'/api/info',
];



export default function request({
	url,
	data,
	method
}) {
	return new Promise((resolve, reject) => {
		let request_obj = null
		let header = {
			'content-type': 'application/json'
		}
		//过滤whiteList中的接口不加token
		let flag = true
		flag = !(whiteList.includes(url))
		if(flag){
			if (getToken()) {
				header = Object.assign(header, {
					'Authorization': 'Bearer ' + getToken()
				})
			}
		}
		let request_base_param = {
			url: base_url + url,
			header,
			method,
			data,
			success: res => {
				const {code} = res.data
				if (code === 200) {
					resolve(res.data);
				} else {
					reject();
				}
			},
		}
		uni.request(request_base_param)
	})
}
